using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using SCSEngine.ResourceManagement;
using SCSEngine.ScreenManagement;
using SCSEngine.ScreenManagement.Implement;
using SCSEngine.Services;
using SCSEngine.Services.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using TextEffect;
using Microsoft.Xna.Framework.Input;

namespace TriUan.TriUanGame.GameScreen
{
    public class CreditScreen: BaseGameScreen
    {
        private SCSServices services;
        private SpriteBatch spriteBatch;
        private InputHandle inputHandle;
        private IResourceManager resourceManager;
        private Texture2D background;
        private SpriteFont font;
        private SpriteFont fontTitle;
        private String creditText;
        private Vector2 textPosition;
        private CTextEffect textEffect;
        private Rectangle textBox;
        public CreditScreen(IGameScreenManager manager)
            :base(manager)
        {
            services = (SCSServices)manager.GamePage.Services.GetService(typeof(SCSServices));
            spriteBatch = services.SpriteBatch;
            inputHandle = services.InputHandle;
            TouchPanel.EnabledGestures = GestureType.Tap;
            resourceManager = (IResourceManager)manager.GamePage.Services.GetService(typeof(IResourceManager));
            this.Init();
        }

        public void Init()
        {
            //Read Text
            this.LoadContent();
            textBox = new Rectangle(120, 150, 555, 230);
            textPosition = new Vector2(textBox.X + 2, textBox.Y + textBox.Height);
            textEffect = new CTextEffect(spriteBatch, font, textPosition, textBox);
            creditText = GameInformation.GetCredit();
            textEffect.InitDrawAlphaBox(true, creditText,20.0f);
        }

        protected override void LoadContent()
        {
            font = resourceManager.GetResource<SpriteFont>("InformationFont");
            fontTitle = resourceManager.GetResource<SpriteFont>("TitleFont");
            background = resourceManager.GetResource<Texture2D>("AboutBackground");
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Draw(background, new Vector2(0, 0), Color.White);
            textEffect.DrawStringHighlight(fontTitle, GameInformation.GetTitle(InformationIndex.TitleCredit), new Vector2(80, 65),Color.Black,Color.Red,2);
            textEffect.DrawAlphaBox(Color.Green,Color.Black);
            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            if (this.GamePage.IsBackKeyPress)
            {
                Manager.RemoveCurrent();

                this.GamePage.IsBackKeyPress = false;
            }

            textEffect.UpdateDrawAlphaBox(gameTime);
            base.Update(gameTime);
        }
    }
}
